package com.cn.yang.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.bean.Personnel;
import com.cn.yang.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/")
public class LoginController {
    @Autowired
    PersonnelService personnelService;
    @RequestMapping("/login")
    public JSONObject login(@RequestBody Personnel personnel,HttpSession session){
        int result = personnelService.login(personnel);
        if (result==1){
            session.setAttribute("personnelNumber",personnel.getPersonnelNumber());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        return jsonObject;
    }
    @RequestMapping("/loginOut")
    public void login(HttpSession session){
        session.setAttribute("personnelNumber","");
    }
}
